<?php
/**
 * Created by PhpStorm.
 * User: Lsen
 * Date: 2018/4/19
 * Time: 13:50
 */
//过期管理控制器
namespace app\admin\controller;

class Outtime extends Common
{
    /**
     * @return \think\response\View
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * 过期列表
     */
    public function index()
    {
        $data = [];
        //搜索
        $order_sn = input('post.order_sn'); //订单编号
        $data['order_sn'] = $order_sn;
        $company_name = input('post.company_name'); //商家名称
        $data['company_name'] = $company_name;
        //页码
        $pageNum = 1;
        if (is_numeric(input('post.pageNum'))) {
            $pageNum = input('post.pageNum');
        }
        $data['pageNum'] = $pageNum;
        //每页数量
        $numPerPage = config('num_per_page');
        $data['numPerPage'] = $numPerPage;
        //列表数据
        $order_model = new \app\admin\model\Outtime();
        $list = $order_model->getList($pageNum, $numPerPage, $order_sn, $company_name);
        $data['list'] = $list['list'];
        $count = $order_model->getCount($order_sn, $company_name);
        $data['count'] = $count;
        return view('',$data);
    }
    /**
     * @return \think\response\View
     * 过期详情
     */
    public function detail()
    {
        $data = [];
        $order_id = input('get.id');
        $reback = db('order')->field('open_id')->where('order_id',$order_id)->find();
        $map['open_id'] = $reback['open_id'];
        $data['dl_info'] = get_info('driving_license', $map, '');
        $data['order_info'] = get_info('order', array('order_id' => $order_id), '');
        return view('', $data);
    }
    /**
     * @return \think\response\Json
     * 平台退款
     */
    public function surereback()
    {
        $reback_id = input('get.id');
        $order = db('order')->field('open_id')->where('order_id', $reback_id)->find();
        $open_id = $order['open_id'];
        try {
            $reback_model = new \app\admin\model\Outtime();
            $reback_model->dosurereback($reback_id, $open_id);
        } catch (Exception $e) {
            return json([
                'statusCode' => 300,
                'message' => $e->getMessage(),
            ]);
        }
        return json([
            'statusCode' => 200,
            'message' => '操作成功',
            'navTabId' => 'outTimeManage'
        ]);
    }
}